package pattern_observer;

public class Reader implements Observer {

	private static int nbReader = 0;
	
	private static String CONST_ID = "reader_";
	private int idNumber;
	private String id;
	
	public Reader() {
		if (id == null) {
			id = CONST_ID;
		}
		idNumber = nbReader;
		nbReader++;
	}
	
	public Reader(String id) {
		this.id = id;
	}
	
	public void inscription(Observable obs) {
		obs.inscrire(this);
	}
	
	public void desinscription(Observable obs) {
		obs.desinscrire(this);
	}
	
	@Override
	public void notifier(Observable observable) {
		// TODO Auto-generated method stub
		String content = "Message from : " + observable.toString() + "\n";
		System.out.println(content);
		read((MailBox) observable);
	}

	public void read(MailBox mx) {
		System.out.println(mx.getMessage());
	}
	
	@Override
	public String toString() {
		String description;
		description = "NiD : " + idNumber + " ID : " + id;
		return description;
	}
	
}
